var namecardlistId=document.URL.split("=")[1];
var namecardlistName=null;



$(function (){
    namecardlistName=$(".nameCardList");

    //名片夹名字验证
    namecardlistName.blur(function (){
        var reg="^[\u4E00-\u9FA5A-Za-z0-9]{1,20}$";
        if(namecardlistName.val().trim().match(reg)){
            $.ajax({
                url: "/nameCardList/nameYZ",
                data: {"namecardlistName":namecardlistName.val().trim()},
                dataType: "json",
                type: "post",
                success:function (result){
                    if(!result){
                        namecardlistName.next().html(" 格式正确");
                    }else {
                        namecardlistName.next().html("名称已存在");
                    }
                }

            })
        }else if(namecardlistName.val()===''){
            namecardlistName.next().html(" 名称不能为空");
        }else {
            namecardlistName.next().html(" 格式错误");
        }
    })

    namecardlistName.focus(function (){
        namecardlistName.next().html("*");
    })

})



var updateName=new Vue({
    el:"#updateName",
    data:{
        nameCardList:''
    },
    methods: {

        update(){
            var flag = true;
            if (namecardlistName.next().html() !== " 格式正确") {
                flag = false;
            }
            var nameCardList1=updateName.nameCardList;
            console.log(nameCardList1);
            var namecard=nameCardList1.trim()
            console.log(namecard)
            //更名
            if (flag){
                axios({
                    method:'POST',
                    url:'http://localhost:8099/nameCardList/updateName',
                    params: {
                        "namecardlistId": namecardlistId,
                        "namecardlistName":namecard,
                    }
                }).then(function (result) {
                    if(result){
                        alert("修改成功");
                        location.href="nameCardList.html"
                    }
                }).catch(function (reason) {
                    console.log(reason);
                })
            }else {
                alert("填写有误");
            }

        }

    }


})

